﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using SCMS.Resource;

namespace SCMS.UI.Models
{
    public class RequestReviewModel
    {
        //List for Approval
        public List<ViewOR> ApprovalOrderRequests { get; set; }
        public List<ViewWRNs> WarehouseReleases { get; set; }
        public List<GRNote> GoodsReceivedNotes { get; set; }

        //Lists for Review
        public List<ViewOR> OrderRequests { get; set; }

        public List<ViewTenders> TenderAnalyses { get; set; }

        public List<ViewPOs> PurchaseOrders { get; set; }

        public List<ViewR4Payment> PaymentRequests { get; set; }

        public List<AdvanceRequestModel> AdvanceRequests { get; set; }        

        public List<ViewExpsClaims> ExpenseClaims { get; set; }

        public List<ViewSalaryPayment> SalaryPayments { get; set; }

        public List<ViewTAForms> TravelAuthorizations { get; set; }

        public List<PPModel> ProcurementPlans { get; set; }

        public List<CompletionCtificate> CompletionCertificates { get; set; }

        //Lists for Authorization
        public List<ViewOR> AuthOrderRequests { get; set; }

        public List<ViewTenders> AuthTenderAnalyses { get; set; }

        public List<ViewPOs> AuthPurchaseOrders { get; set; }

        public List<ViewR4Payment> AuthPaymentRequests { get; set; }

        public List<AdvanceRequestModel> AuthAdvanceRequests { get; set; }

        public List<ViewWRNs> AuthWarehouseReleases { get; set; }

        public List<ViewExpsClaims> AuthExpenseClaims { get; set; }

        public List<ViewSalaryPayment> AuthSalaryPayments { get; set; }

        public List<ViewTAForms> AuthTravelAuthorizations { get; set; }        

    }

    public class ReviewOR
    {
        public ORequester ORequest { get; set; }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy h:mm tt}")]
        public DateTime? ORDate
        {
            get { return ORequest.EntityOrderRequest.PreparedOn; }
        }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}")]
        public DateTime? DeliveryDate
        {
            get { return ORequest.EntityOrderRequest.DeliveryDate; }
        }

        [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Global_String_Required")]
        public Guid ProjectId { get; set; }
        public SelectList Projects { get; set; }

        [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Global_String_Required")]
        public Guid? ProjectDonorId { get; set; }
        public SelectList ProjectNos { get; set; }

        public List<ReviewOrderRequestItem> ORItems { get; set; }

        public SelectList Currencies { get; set; }

        public string MBCurrencyId { get; set; }

        [DataType(DataType.Currency)]
        [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Global_String_Required")]
        public decimal? MbValue { get; set; }

        public string DonorName { get; set; }

        public bool IsFinanceReview { get; set; }

        public List<Model.BudgetCheckResult> BudgetCheckResults { get; set; }
    }

    public class ReviewOrderRequestItem
    {
        public SCMS.Model.OrderRequestItem EntityOrderRequestItem { get; set; }

        [DataType(DataType.Text)]
        public string Description { get; set; }
        
        public string UnitMessureID { get; set; }
        public SelectList UnitMessures { get; set; }

        [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Global_String_Required")]
        public decimal Quantity { get; set; }
        
        [DataType(DataType.Currency)]
        [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Global_String_Required")]
        public decimal UnitPrice { get; set; }

        [DataType(DataType.Currency)]
        [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Global_String_Required")]
        public decimal TotalPrice { get; set; }

        [Required]
        public string ProjectNoID { get; set; }
        public SelectList ProjectNos { get; set; }

        [Required]
        public string BudgetLineID { get; set; }
        public SelectList BudgetLines { get; set; }

        [DataType(DataType.Text)]
        public string Remarks { get; set; }

        public Guid OrderRequestItemId { get; set; }
    }

    public class ReviewPO
    {
        public ViewPOs ViewPO { get; set; }

        public List<ReviewPOItem> POItems { get; set; }

        public SelectList Currencies { get; set; }

        public string MBCurrencyId { get; set; }

        public decimal? MbValue { get; set; }

        public List<Model.BudgetCheckResult> BudgetCheckResults { get; set; }

    }

    public class ReviewPOItem
    {
        public Model.PurchaseOrderItem EntityPOItem { get; set; }

        public string ItemName 
        {
            get
            {
                if (EntityPOItem.OrderRequestItem != null)
                    return EntityPOItem.OrderRequestItem.Item.Name;
                else
                    return Resources.Global_String_TransportCost;

            }
            set { EntityPOItem.OrderRequestItem.Item.Name = value; } 
        }

        public Guid POItemId { get; set; }

        [Required]
        [DataType(DataType.Currency)]
        public double UnitCost { get; set; }

        [Required]
        public int Quantity { get; set; }

        public string UnitOfMeasure { get; set; }

        [Required]
        [DataType(DataType.Currency)]
        public decimal TotalCost { get; set; }

        public Guid? BudgetLineId { get; set; }

        public SelectList BudgetLines { get; set; }

        public string Remarks { get; set; }
    }

    public class ReviewRFP
    {
        public Model.PaymentRequest EntityPaymentRqst { get; set; }

        public List<ReviewRFPDetails> paymentDetails { get; set; }

        public Guid MBCurrencyId { get; set; }
        public SelectList Currencies { get; set; }
        public decimal? MBValue { get; set; }

        public List<Model.BudgetCheckResult> BudgetCheckResults { get; set; }
    }

    public class ReviewRFPDetails
    {
        [DataType(DataType.Currency)]
        [Required]
        public decimal Amount { get; set; }
        public Guid BudgetLineId { get; set; }
        public SelectList BudgetLines { get; set; }
        public Guid ProjectDonorId { get; set; }
        public SelectList ProjectDonors { get; set; }
        public Guid RFPDetailId { get; set; }
    }
}